<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 130px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            background-color: pink;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div class="box">王燕是个大傻妞</div>

    <script>
        // 获取Dom
        const box = document.querySelector('.box')

        // 给window绑定鼠标经过事件,拿到鼠标的X/Y坐标
        window.onmousemove = function (e) {
            // 将鼠标的X/Y值赋给盒子的定位值,减掉盒子宽高的一半,就是居中位置
            box.style.left = e.clientX - box.clientWidth / 2 + 'px'
            box.style.top = e.clientY - box.clientHeight / 2 + 'px'
            console.log(e.clientX);
        }
    </script>
</body>

</html>